import { useContext } from 'react';
import Ctx from '.';

export default function (stateFields, Component) {
    return function (props) {
        const { state, setState } = useContext(Ctx);
        const usefulState = {};
        for (const field of stateFields) {
            usefulState[field] = state[field];
        }
        return <Component { ...props } ctx={[usefulState, setState]} />;
    };
}
